home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / 1OUJ6AB (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  1.2 KB  |  36 lines

  1. package java.util;
  2.  
  3. public class Stack extends Vector {
  4.    private static final long serialVersionUID = 1224463164541339165L;
  5.  
  6.    public boolean empty() {
  7.       return ((Vector)this).size() == 0;
  8.    }
  9.  
  10.    public synchronized Object peek() {
  11.       int len = ((Vector)this).size();
  12.       if (len == 0) {
  13.          throw new EmptyStackException();
  14.       } else {
  15.          return ((Vector)this).elementAt(len - 1);
  16.       }
  17.    }
  18.  
  19.    public synchronized Object pop() {
  20.       int len = ((Vector)this).size();
  21.       Object obj = this.peek();
  22.       ((Vector)this).removeElementAt(len - 1);
  23.       return obj;
  24.    }
  25.  
  26.    public Object push(Object item) {
  27.       ((Vector)this).addElement(item);
  28.       return item;
  29.    }
  30.  
  31.    public synchronized int search(Object o) {
  32.       int i = ((Vector)this).lastIndexOf(o);
  33.       return i >= 0 ? ((Vector)this).size() - i : -1;
  34.    }
  35. }
  36.